def success_response(data=None, message="Success"):
    return {
        'result': True,
        'data': data,
        'message': message,
        'error_code': 200
    }

def error_response(message="Error", status_code=400):
    return {
        'result': False,
        'message': message,
        'error_code': status_code
    }


def convert_size(text):
    """
    文件大小单位换算
    :text: 文件字节
    :return: 返回字节大小对应单位的数值
    """
    units = ["B", "KB", "MB", "GB", "TB", "PB"]
    size = 1024
    for i in range(len(units)):
        if (text / size) < 1:
            return "%.2f%s" % (text, units[i])  # 返回值保留小数点后两位
        text = text / size

